package com.leyou.item.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.leyou.item.dto.CategoryDTO;
import com.leyou.item.entity.Category;
import com.leyou.item.mapper.CategoryMapper;
import com.leyou.item.service.CategoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;

/**
 * <p>
 * 商品类目表，类目和商品(spu)是一对多关系，类目与品牌是多对多关系 服务实现类
 * </p>
 *
 * @author MyBatisPlusGenerater
 * @since 2020-11-07
 */
@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {

    @Override
    public List<CategoryDTO> querycategoryBypid(Long pid) {
        // select * form category where parent_id = #{pid}
        List<Category> parentId = query().eq("parent_id", pid).list();

        //pojo转化为DTO
        return CategoryDTO.convertEntityList(parentId);
    }

    @Override
    public CategoryDTO querycategoryByid(Long id) {
        //select *form category where id =#{id}
        CategoryDTO categoryDTO = new CategoryDTO(getById(id));
        return categoryDTO;
    }

    @Override
    public List<CategoryDTO> querycategorylist(List<Long> ids) {

        return CategoryDTO.convertEntityList(listByIds(ids));
    }


}
